﻿using System ;
using Microsoft.Practices.Prism.Logging ;
using System.IO.IsolatedStorage ;
using System.ComponentModel.Composition;

namespace OpenLightGroup.Prism
{
     [PartCreationPolicy(CreationPolicy.Shared)]
     [Export("IsolatedStorageLogger", typeof(ILoggerFacade))]
    public class IsolatedStorageLogger : ILoggerFacade
    {

        #region ILoggerFacade Members

        public void Log ( string message, Category category, Priority priority )
        {
            using ( var store = IsolatedStorageFile.GetUserStoreForApplication( ) )
                using ( var file = store.OpenFile( "log.txt", System.IO.FileMode.Append ) )
                    using ( var writer = new System.IO.StreamWriter( file ) )
                    {
                       
                        writer.WriteLine( String.Format( "{0} : {1} - {2}: {3}", DateTime.Now.ToString( ), priority.ToString( ), category.ToString( ), message ) ) ;

                        writer.Close( ) ;

                    }
        }

        #endregion
    }
}